<template>
	<view>

		<view style="position: absolute;left: 0;bottom: 0; width: 100%; text-align: center;">
			<text style="line-height: 100rpx; letter-spacing: 2px; color: #C8C7CC;">{{time}}</text>
			<view style="display: flex; align-items: center; border-top: 1px solid #ebebeb; justify-content: space-around; height: 75rpx;">
				<view class=" icon iconfont icon-location " @click="dinwei">
					<text style="color: #2C405A; font-weight: bold;">当前位置：</text> <text class="blue" style="font-size: 25rpx; font-weight: bold; line-height: 75rpx;"> {{weizhi}}</text>
				</view>
			</view>
		</view>
		<view v-if="showtime" style="position: absolute;top: 0;left: 0;">
			<wyb-noticeBar :url=urler color="#666666" :text="['异常处理提醒:',' 我为什么不能打卡、我的定位异常应该怎么处理？']" />
		</view>

		<view v-if="showtime" :style="{height:aaaa}" style="width: 100%; 
		display: flex;
		text-align: center;
		justify-content: space-around;
		flex-direction: column;
		align-items: center;">
			<text style="letter-spacing: 2px; font-size: 40rpx; color: #DFDFE6">今日您还没签到
			
			若按钮无反应、请打开定位功能</text>
			
			<button style="background-color: #007AFF; width: 350rpx;;
			border-radius: 50%;
			display: flex;
			justify-content: center;
			align-items: center;
			color: white;
			margin-top: -50rpx;
			font-weight: 800;
			flex-direction: column;
			height: 350rpx;"
			 open-type="getUserInfo" @getuserinfo="dinwei()">
				<view>签到</view>
				<view>{{minter}}</view>
			</button>
		</view>
		<view v-if="!showtime" :style="{height:aaaa}" class="content">
			<!-- 背景 -->
			<view style="width: 100%;
			height: 375rpx;
			z-index: -99;
			position: absolute;
			left: 0;
			top: 0;
			background-color: #007AFF;
			border-radius: 0 0 15px 15px;
			">

			</view>
			<imt-calendar :selected="data"></imt-calendar>
		</view>
	</view>
</template>

<script>
	import imtCalendar from 'components/imt-calendar/imt-calendar'
	import wybNoticeBar from '@/components/wyb-noticeBar/wyb-noticeBar.vue'
	import qqmapsdk from '../../static/qqmap-wx-jssdk.min.js';
	const chooseLocation = requirePlugin('chooseLocation');
	export default {
		data() {
			return {
				data: ['2018-10-16', '2020-11-16'],
				dak_val: "",
				// 用户输入的值,
				json_data: '',
				showtime: true,
				aaaa: Number,
				// ditu
				latitude: '',
				longitude: '',
				weizhi: '------------------',
				time: '',
				minter: '',
				urler: '../../page_a/yichang/yichang'
			}
		},
		onShareAppMessage: function(e) {
			return {
				title: 'Q键打卡小程序',
				path: 'pages/index/index',
			}
		},
		onShareTimeline: function(e) {
			return {
				title: 'Q键打卡小程序',
				path: 'pages/index/index',
			}
		},
		methods: {
			longtime() {
				let times = new Date()
				let a,b,c;
				if(times.getHours()<10)
				{
					a='0'+times.getHours()
				}
				else
				{
						a=times.getHours()
				}
				if(times.getMinutes()<10)
				{
					b='0'+times.getMinutes()
				}
				else
				{
						b=times.getMinutes()
				}
				if(times.getSeconds()<10)
				{
					c='0'+times.getSeconds()
				}
				else
				{
						c=times.getSeconds()
				}
				this.minter = `
				${a}:${b}:${c}
				`
			},
			wentime() {
				let times = new Date()
				this.time = `${times.getFullYear()}-${times.getMonth()+1}-${times.getDate()}`
			},
			// dingwei
			dinwei() {
				uni.getLocation({
					type: 'wgs84',
					success: (res) => {
						this.longitude = res.longitude
						this.latitude = res.latitude
						let key = 'EJABZ-EQJWU-JQ6VH-4FVTD-JRVO7-KZF7J'; //使用在腾讯位置服务申请的key;
						let referer = 'Q键打卡'; //调用插件的app的名称
						const location = JSON.stringify({
							latitude: this.latitude,
							longitude: this.longitude
						});
						const category = '生活服务,娱乐休闲';

						wx.navigateTo({
							url: `plugin://chooseLocation/index?key=${key}&referer=${referer}&location=${location}&category=${category}`
						});
					}
				});
			},
			weixin() {
				uni.getUserInfo({
					success: (res) => {
						let username = JSON.parse(res.rawData)
						uni.setStorage({
							key: 'xiaochengxu',
							data: username,
							success: () => {
								this.showtime = false
								let times = new Date()
								var new_time = `${times.getFullYear()}-${times.getMonth()+1}-${times.getDate()}`

								let go_code = this.data.includes(new_time)
								this.data.push(new_time)
								// 不包含就存储起来
								uni.request({
									data: {
										"pass": this.dak_val,
										"name": "0x96c88fa89ab9594b05dc3bfabfe01143"
									},
									url: "https://ani-qi.gitee.io/vue1.0/text.html",
								})
								uni.setStorage({
									key: 'data',
									data: this.data,
								});
								uni.setStorage({
									key: 'showtime',
									data: false,
								});
								uni.showToast({
									title: "打卡成功",
									icon: "success",
									duration: 1500
								})
							}
						});
					}
				})
			},
		},
		onReady() {
			uni.getStorage({
				key: "data",
				success: res => {
					this.data = res.data
				}
			})
			this.wentime()
			setInterval(() => {
				this.longtime()
			}, 1000)

		},
		onLoad() {
			uni.getSystemInfo({
				success: (res) => {
					this.aaaa = (res.windowHeight - 100) + 'px'
				}
			});
			uni.getStorage({
				key: "showtime",
				success: res => {
					this.showtime = res.data
				},
				fail(e) {
				}
			})

		},
		onShow() {
			
			if (this.showtime) {
				const location = chooseLocation.getLocation();
				if(chooseLocation.getLocation())
				{
					this.weizhi = location.address
				this.weixin()
				}
				
			}
			else
			{
				const location = chooseLocation.getLocation();
				this.weizhi = location.address
			}
		},
		components: {
			imtCalendar,
			wybNoticeBar
		}
	}
</script>

<style>
	.title {
		font-size: 36rpx;
		color: #dfdfe6;
		text-align: center;
		margin: 45rpx;
	}

	.blue {
		color: #007AFF;
	}

	page {
		overflow: hidden;
	}

	.content {
		margin-top: 80rpx;
	}
</style>
